<%@page import="br.com.Modelo.UsuarioCliente"%>
<%@page import="java.util.List"%>
<%@page import="br.com.Modelo.Produto"%>
<%@page import="br.com.Modelo.UsuarioComerciante"%>
<%@page import="br.com.Modelo.Pagina"%>
<%@page import="br.com.Modelo.Endereco"%>
<%@page import="br.com.Dao.UsuarioClienteDao"%>
<%@page import="br.com.Dao.UsuarioComercianteDao"%>
<%@page import="br.com.Dao.ProdutoDao"%>
<%@page import="br.com.Dao.PaginaDao"%>
<%@page import="br.com.Dao.EnderecoDao"%>
<%@page import="java.io.IOException"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>SB Admin - Bootstrap Admin Template</title>

    <!-- Bootstrap Core CSS -->
    <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="../public/css/sb-admin.css" rel="stylesheet">

    <!-- Morris Charts CSS -->
    <link href="../public/css/plugins/morris.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="../public/font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    
      
<script type="text/javascript" src="../public/js/jquery.js"></script>
<link href="../bootstrap/css/bootstrapValidator.css" rel="stylesheet">

<script type="text/javascript" src="../bootstrap/js/bootstrapValidator.js"></script>
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    
    
    
    <style>
    .btn-primary {
	color: #ffffff;
	text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
	background-color: #229ac8;
	background-image: linear-gradient(to bottom, #23a1d1, #1f90bb);
	background-repeat: repeat-x;
	border-color: #1f90bb #1f90bb #145e7a;
}

.btn-primary:hover,.btn-primary:active,.btn-primary.active,.btn-primary.disabled,.btn-primary[disabled]
	{
	background-color: #1f90bb;
	background-position: 0 -15px;
}
    
    .main-box.no-header {
    padding-top: 20px;
}
.main-box {
    background: #FFFFFF;
    -webkit-box-shadow: 1px 1px 2px 0 #CCCCCC;
    -moz-box-shadow: 1px 1px 2px 0 #CCCCCC;
    -o-box-shadow: 1px 1px 2px 0 #CCCCCC;
    -ms-box-shadow: 1px 1px 2px 0 #CCCCCC;
    box-shadow: 1px 1px 2px 0 #CCCCCC;
    margin-bottom: 16px;
    -webikt-border-radius: 3px;
    -moz-border-radius: 3px;
    border-radius: 3px;
}
.table a.table-link.danger {
    color: #e74c3c;
}
.label {
    border-radius: 3px;
    font-size: 0.875em;
    font-weight: 600;
}
.user-list tbody td .user-subhead {
    font-size: 0.875em;
    font-style: italic;
}
.user-list tbody td .user-link {
    display: block;
    font-size: 1.25em;
    padding-top: 3px;
    margin-left: 60px;
}
a {
    color: #3498db;
    outline: none!important;
}
.user-list tbody td>img {
    position: relative;
    max-width: 50px;
    float: left;
    margin-right: 15px;
}

.table thead tr th {
    text-transform: uppercase;
    font-size: 0.875em;
}
.table thead tr th {
    border-bottom: 2px solid #e7ebee;
}
.table tbody tr td:first-child {
    font-size: 1.125em;
    font-weight: 300;
}
.table tbody tr td {
    font-size: 0.875em;
    vertical-align: middle;
    border-top: 1px solid #e7ebee;
    padding: 12px 8px;
}
    
    
    </style>
    
     <script type="text/javascript">


$(document).ready(function(){
	$("#mytable #checkall").click(function () {
	        if ($("#mytable #checkall").is(':checked')) {
	            $("#mytable input[type=checkbox]").each(function () {
	                $(this).prop("checked", true);
	            });

	        } else {
	            $("#mytable input[type=checkbox]").each(function () {
	                $(this).prop("checked", false);
	            });
	        }
	    });
	});

	 $(function () {
	            $("[rel='tooltip']").tooltip();
	        });


	 $(document).ready(function() {
			//$('#p').click(function() {
				$("#delete").on('show.bs.modal', function(event) {
					var button = $(event.relatedTarget);
					var recipient = button.data('whatever');
					
							$('#id_produto').val(recipient);

						
					})
			
		});

</script>
</head>

<body>



	<%
		///allow access only if session exists
	    
		String[] id = (String[]) session.getAttribute("user");
	    
		UsuarioCliente userCliente = null;
		UsuarioComerciante userComerciante = null;

		UsuarioComercianteDao dao = new UsuarioComercianteDao();
		if (id != null) {
			
			if (id[1].equals("1")) {


			} else {

		   userComerciante = dao.validaAutenticacaoUser(
		Long.parseLong(id[0]), Integer.parseInt(id[1]));
			}
		}
		String userName = null;
		String sessionID = null;
		
		if (userComerciante != null) {
			Pagina pagina = new Pagina();
			PaginaDao paginaDao= new PaginaDao();
			//out.println(userComerciante.getIdPagina());
			pagina = paginaDao.getPagina(userComerciante.getIdPagina());
			
			if(pagina != null){
		  //  pagina = new PaginaDao().getPagina(userComerciante.getIdPagina());
		      ProdutoDao  daoProduto = new ProdutoDao();
		  		List<Produto> produtos = daoProduto.getProdbyPagina(pagina.getPagina());
	%>




	<div id="wrapper">

		<!-- Navigation -->
		<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
		<!-- Brand and toggle get grouped for better mobile display -->
		<div class="navbar-header">
			<button type="button" class="navbar-toggle" data-toggle="collapse"
				data-target=".navbar-ex1-collapse">
				<span class="sr-only">Toggle navigation</span> <span
					class="icon-bar"></span> <span class="icon-bar"></span> <span
					class="icon-bar"></span>
			</button>
			<a class="navbar-brand" href="">Painel Administrativo</a>
		</div>
		<!-- Top Menu Items -->
		<ul class="nav navbar-right top-nav">


				<li class="dropdown"><a class="dropdown-toggle" role="button"
				data-toggle="dropdown" href="#"> <i
					class="glyphicon glyphicon-user"></i> <%=userComerciante.getLogin()%>
					<span class="caret"></span></a>
				<ul id="g-account-menu" class="dropdown-menu" role="menu">
					<li><a href="#">Meu Perfil</a></li>
					<li><a href="/plataforma_marketing/LogoutServlet"><i class="glyphicon glyphicon-lock"></i>
							Sair</a></li>
				</ul></li>
		</ul>
		<!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
		<div class="collapse navbar-collapse navbar-ex1-collapse">
			<ul class="nav navbar-nav side-nav">
				<li class="co"><a href="/plataforma_marketing"><img
						src="/plataforma_marketing/img/logo.png"></img> </a></li>

				<li class=""><a href="admin_loja.jsp"><i
						class="fa fa-fw fa-file"></i> Configurações Pagina</a></li>

				<li><a href="javascript:;" data-toggle="collapse"
					data-target="#demo"><i class="fa fa-fw fa-arrows-v"></i>
						Produto<i class="fa fa-fw fa-caret-down"></i></a>

					<ul id="demo" class="collapse">
						<li><a href="cadastrar_produto.jsp"><i
								class="glyphicon glyphicon-plus"></i> Cadastrar Produto</a></li>

						<li><a href="editar_produto.jsp"><i
								class="glyphicon glyphicon-cog"></i> Editar Produto</a></li>

					</ul></li>
				<li><a href="config_admin.jsp"><i
						class="glyphicon glyphicon-plus"></i> Configurações Admin</a></li>


  	<li id="ir"><a href="/plataforma_marketing/<%=pagina.getPagina()%>"><i class="glyphicon glyphicon-transfer"></i>
					  Ir para Pagina</a></li>
               
                

			</ul>
		</div>
		<!-- /.navbar-collapse --> </nav>

		<div id="page-wrapper">

			<div class="container-fluid" style="height: 1000px">

				<!-- Page Heading -->
				<div class="row">


					<div class="panel panel-default">
						<div class="panel-heading">
							<div class="panel-title">
								<i class="glyphicon glyphicon-wrench pull-right"></i>
								<h4>Editar Produto</h4>
							</div>
						</div>
						<div class="panel-body">


                                                <div class="col-md-12">


</div>


        <div class="main-box no-header clearfix">
                <div class="main-box-body clearfix">
                    <div class="table-responsive">
                        <table class="table user-list">
                            <thead>
                                <tr>
                                <th><span>Produto</span></th>
                                   <th>Nome</th>                
                    		  <th>Edit</th>
                       <th>Delete</th>
                                <th>&nbsp;</th>
                                </tr>
                            </thead>
                            <tbody>
                                
    			<%if(!produtos.isEmpty()){%>
    			<% for(Produto produto : produtos){ %>
                                <tr>
                                    <td>
                                        <img src="/plataforma_marketing/img/product/<%=produto.getImagem_produto()%>" alt="">
                                    
                                    </td>                               
                                       <td><h4><%=produto.getNome_produto()%></h4></td>
                                        <td><p><a class="btn btn-primary btn-xs" href="atualizar_produto.jsp?id_produto=<%=produto.getId_produto()%>"><span class="glyphicon glyphicon-pencil"></span> Editar</a></p></td>
    <td><p><a class="btn btn-danger btn-xs" data-title="Delete" data-toggle="modal" data-target="#delete" data-placement="button" id="btnedit" data-whatever="<%=produto.getId_produto()%>" data-placement="button" rel="tooltip"><span class="glyphicon glyphicon-trash"></span>Remover</a></p></td>
                                   
                                </tr>
                                
                                  
  						 <% } } %>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
</div>

	<!--  editar enderco -->
							<!-- Modal -->
							<div class="modal fade" id="edit" tabindex="1000"
								role="dialog" aria-labelledby="" aria-hidden="">
								<
								
								div class="modal-dialog">
									<div class="modal-content">
										<form class="form form-horizontal" method="post" action="uploadImgProduto"
								enctype="multipart/form-data">
							   <label class="col-md-2 control-label" for="descricao_empresa">Imagem Produto</label>		
							  						
								<!-- <input type="hidden" name="idPagina"<%//=userComerciante.getIdPagina()%>" /> -->
									<span class="btn btn-default btn-file"> <input type="file" 	name="file" size="60">
                                       </span>
                                
							

										<button type="submit" class="btn btn-primary">Enviar 
										</button>								
								
							</form>
									
									
										<form id="myform" class="form-horizontal" action="editar_end"
											method="post">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal">
													<span aria-hidden="true">&times;</span><span
														class="sr-only">Close</span>
												</button>
												<h4 class="modal-title" id="myModalLabel">Editar
													Produto</h4>
											</div>
											<div class="modal-body">



												<!-- Text input-->
												<div class="form-group">
													<label class="col-md-2 control-label" for="login_empresa">Nome
													</label>
													<div class="col-md-5">
														<input name="nome" id="nome" type="text"
															class="form-control input-md">
													</div>
												</div>

												<!-- Select Basic -->
									<div class="form-group">
										<label class="col-md-2 control-label" for="ramo_empresa">Tipo
											Produto</label>
										<div class="col-md-5">
											<select id="ramo_empresa" name="tipo_produto"
												class="form-control">
												<option value="roupas">Loja de Roupas</option>
												<option value="sapatos">Sapataria</option>
												<option value="moveis_eletros">Móveis e Eletrodomésticos</option>
												<option value="supermercados">Supermercado</option>
												<option value="eletronicos">Eletronicos</option>
											</select>
										</div>
									</div>


									<!-- Text input-->
									<div class="form-group">
										<label class="col-md-2 control-label" for="cnpj">Descrição
											Produto</label>
										<div class="col-md-8">

											<textarea class="jqte-test" name="descricao_produto" ><b>Descrição Produto <u><span
														style="color: rgb(0, 148, 133);">TEXTAREA</span></u></b></textarea>
										</div>
									</div>

									<!-- Password input-->
									<div class="form-group">
										<label class="col-md-2 control-label" for="senha_confirma">Tipo
											Preço Produto</label>
										<div class="col-md-5">
											<select id="ramo_empresa" name="tipo_preco"
												class="form-control">
												<option value="1">Normal</option>
												<option value="2">Promoção</option>
											</select>
										</div>
									</div>


									<!-- Textarea -->
									<div class="form-group">
										<label class="col-md-2 control-label" for="descricao_empresa">Preço
											Normal Produto</label>
										<div class="col-md-4">

											<input id="end" name="preco_produto" type="text"
												placeholder="0.00" class="form-control input-md">
										</div>
									</div>


									<!-- Textarea -->
									<div class="form-group">
										<label class="col-md-2 control-label" for="descricao_empresa">Preço
											Promoçao</label>
										<div class="col-md-4">

											<input id="end" name="preco_produto_p" type="text"
												placeholder="0.00" class="form-control input-md">
										</div>
									</div>

												<input type="hidden" id="count" name="count"/>
												<input type="hidden" id="id_pagina" name="id_pagina" />
												<input type="hidden" id="id_end" name="id_end"/>

												</fieldset>


											</div>

											<div class="modal-footer">
												<button type="button" class="btn btn-default"
													data-dismiss="modal">Close</button>
												<button type="submit" class="btn btn-primary">Save
													changes</button>
											</div>
										</form>
									</div>
								</div>
							</div>



							<!-- / editar endereco -->



<div class="modal fade" id="delete" tabindex="1" role="dialog" aria-labelledby="edit" aria-hidden="true">
      <div class="modal-dialog">
    <div class="modal-content">
    

          <div class="modal-header">
               <form action="remover_produto" method="POST">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h4 class="modal-title custom_align" id="Heading">Delete this entry</h4>
      </div>
          <div class="modal-body">
       
       <div class="alert alert-warning"><span class="glyphicon glyphicon-warning-sign"></span> Vocẽ realmente deseja remover o produto ?</div>
       <input type="hidden" id="id_produto" name="id_produto">
      </div>
        <div class="modal-footer ">
        <button type="submit" class="btn btn-success" ><span class="glyphicon glyphicon-ok-sign"></span> Yes</button>
        <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> No</button>
      </div>
         </form>
        </div>
   
    <!-- /.modal-content --> 
  </div>
      <!-- /.modal-dialog --> 
    </div>

						</div>
						<!--/panel content-->
					</div>
					<!--/panel-->



				</div>
				<!-- /.row -->



			</div>
			<!-- /.container-fluid -->

		</div>
		<!-- /#page-wrapper -->

	</div>
	<!-- /#wrapper -->
	<script type="text/javascript" src="../bootstrap/js/bootstrapValidator.js"></script>
	

 
  
    <!-- jQuery Version 1.11.0 -->

	<script src="../bootstrap/js/jquery-1.11.0.js"></script>
	<script src="../bootstrap/js/bootstrap.js"></script>



    
    <%
		}}
	%>

</body>

</html>